#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>

int main(int argc,char* argv[])
{
  int tcp_fd = socket(AF_INET,SOCK_STREAM,0);
  if(tcp_fd < 0)
  {
    perror("socket fail");
    return -1;
  }
  
  struct sockaddr_in server_addr;
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(50000);
  inet_pton(AF_INET,argv[1],&server_addr.sin_addr);

  int con_fd = connect(tcp_fd,(struct sockaddr*)&server_addr,sizeof(server_addr));

  int file_fd = open(argv[2],O_RDWR);
  send(tcp_fd,argv[2],strlen(argv[2]),0);
  char buf[1024];
  int ret;
  while(1)
  {
    ret = read(file_fd,buf,1024);

    if(ret == 1024)
    {
      send(tcp_fd,buf,1024,0);
    }else if(ret < 1024)
    {
      send(tcp_fd,buf,strlen(buf),0);
      break;
    }
  }


  close(file_fd);
  close(tcp_fd);
  return 0;
}
